package njust.hitcourse;

import njust.course.Course;
import njust.user.Login;
import njust.utils.DBUtil;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HitCourseDAO {
    public HitCourseDAO(){}
    public void addHitCourse(int uId,int cId,int score){
        Map<String,Object> map=new HashMap<>();
        map.put("uId",uId);
        map.put("cId",cId);
        map.put("score",score);
        try {
            DBUtil.insert("hitcourse",map);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public void delHitCourse(int uId,int cId){
        Map<String,Object> map=new HashMap<>();
        map.put("uId",uId);
        map.put("cId",cId);
        try {
            DBUtil.delete("hitcourse",map);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void updateCourse(Map<String,Object> valueMap,Map<String,Object> whereMap){
        try {
            DBUtil.update("course",valueMap,whereMap);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public List<Map<String, Object>> getListCourseByUserId(int uId){
        Map<String,Object> map=new HashMap<>();
        map.put("uId",uId);
        try {
            List<Map<String, Object>> hitcourses = DBUtil.query("hitcourse", map);
            return hitcourses;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public HitCourse getHitCourseByIds(int uId,int cId){
        Map<String,Object> map=new HashMap<>();
        map.put("uId",uId);
        map.put("cId",cId);
        try {
            List<Map<String, Object>> hitcourse = DBUtil.query("hitcourse", map);
            new HitCourse((int) hitcourse.get(0).get("uId"),(int) hitcourse.get(0).get("cId"), (Integer) hitcourse.get(0).get("score"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
